<?php
require_once(APPPATH.'models/baseModel.php');
class UserPlacemodel extends BaseModel
{
    
    private static $cols = "id,pressure,a,c_date,u_uid, phone_id";

    function __construct()
    {
        parent::__construct();
    }

    function  countAll($table){
        return $this->db->from($table)->count_all_results();
    }

    function listmap($table){
        $array=$this->db->get($table)->result_array();
        $map=array();
        foreach ($array as $user) {
            $map[$user['id']]=$user;
        }
        return $map;
    }


    function  getById($table,$id){
        $this->db->where("id", $id);
        return $this->db->get($table)->row_array();
    }


    function insert($table,$data)
    {
        $result=$this->db->insert($table,$data);
        return $result;
    }

    function insertBatch($table,$data)
    {
        $result=$this->db->insert_batch($table,$data);
        return $result;
    }

    function update($table,$data, $id)
    {
        $this->db->where("id", $id);
        $result=$this->db->update($table,$data);
        return $result;
    }

    function updateBatch($table,$data,$where)
    {
        foreach ($data as $item) {
            $this->db->where("pid", $item['pid']);
            $result=$this->db->update($table,array('uid' => $item['uid'], 'c_time' => $item['c_time']));
            if (!$result) {
                return $result;
            }
        }

        return true;
    }

    function delete($id)
    {
        $this->db->where("id",$id);
        $result=$this->db->delete($table);
        return $result;
    }

    function  lists(){
        $list=$this->db->get($table)->result_array();
        $map=array();
        foreach($list as $l){
            $map[$l['key']]=$l['value'];
        }
        return $map;
    }

    function countByCondition($where)
    {
        $sql="select count(1) as num from ".$table." where 1=1  ".$where;
        $row=$this->db->query($sql)->row_array();
        return $row['num'];
    }



}